<template>
	<view class="main">
		<u-navbar :is-back="true" title="分类管理" :background="background" back-icon-color="#000000" title-color="#000"
			title-bold="true"></u-navbar>
		<view class="lists">
			<view class="content" v-for="(item,index) in typelist" :key="index">
				<text>{{item.name}}</text>
				<image src="../../../static/images/remove.png" @click="showmodle(item.id)"></image>
			</view>
		</view>
		<view class="confirm" @click="router">
			添加分类
		</view>
		<u-modal v-model="show" cancel-text="再想想" title="温馨提示" @confirm="confirm" show-cancel-button="true"
			cancel-color="#FE4E00" border-radius="20" :mask-close-able="true" :content="content"></u-modal>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#fff'
				},
				show: false,
				content: '确认删除分类',
				typelist: [],
				remove_id: '',
			}
		},
		onLoad() {


		},
		mounted() {

		},
		onShow() {
			this.gettypelist()
		},
		methods: {
			showmodle(id) {
				this.show = true
				this.remove_id = id
			},
			gettypelist() {
				global.$http.request({
					url: '/shopapi/goods/goodsCategorylist',
					data: {
						token: uni.getStorageSync('token'),	
						shop_id: uni.getStorageSync('userinfo').shop_info.shop_id
					}
				}).then(res => {
					if (res.data.code == 200) {
						console.log(res.data.data);
						this.typelist = res.data.data
					}
				})
			},
			confirm() {
				console.log(222222);
				global.$http.request({
					url: '/shopapi/goods/goodsCategorydel',
					data: {
						id: this.remove_id,
						token: uni.getStorageSync('token')
					}
				}).then(res => {
					if (res.data.code == 200) {
						console.log(res.data.data);
						uni.showToast({
							title:res.data.msg,
							icon:'none',
							duration:1000
						})
						let that=this
						setTimeout(function(){
								that.gettypelist()
						},1000)
					}
					
				})
			},
			router() {
				uni.navigateTo({
					url: '../add_type/add_type'
				})
			}
		}
	}
</script>
<style lang="scss">
	page {
		font-family: PingFang SC;
		width: 750rpx;
		margin: 0 auto;

		background-color: #f7f7f7;

		.main {
			width: 750rpx;
			margin: 0 auto;

			.lists {
				margin: 10rpx 0 150rpx 0;

				.content {
					padding: 30rpx;
					background-color: #fff;
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 28rpx;
					font-weight: 400;
					color: #000000;
					margin-bottom: 2rpx;

					image {
						width: 18rpx;
						height: 18rpx;
					}
				}
			}

			.confirm {
				position: fixed;
				bottom: 0;
				width: 750rpx;
				text-align: center;
				padding: 34rpx 0;
				background: #FE4E00;
				font-size: 32rpx;
				font-weight: 400;
				color: #FFFFFF;

			}
		}
	}
</style>
